<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="ssm" uri="http://ssm.elangzhi.com/jsp/tag/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
2017年5月23日  闫增宝
Created by GaoXiang
Date: 2017-05-23 14:06:05 星期二
Version: 1.0
停车位编辑页面
--%>
<link href="/static/sign/css/signStyle.css" rel="stylesheet">
<div class="portlet light" >
    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="edit-module">
            <div class="form-body">

                <div class="row">
                    <div class="col-md-6 hide">
                        <div class="form-group">
                            <label class="control-label col-md-3">ID</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" name="id" value="${data.id}" placeholder="默认生成，ID">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">所属停车场</label>
                            <div class="col-md-9">
                                <c:if test="${type != 6}">
                                <div class="input-group">
                                    <div class="input-icon">
                                        <i class="fa fa-lock fa-fw"></i></c:if>

                                        <input id="parkingId" class="form-control" type="hidden" name="parkingId"  value="${data.parkingId}"
                                        <c:if test="${type == 6}"> value="${data.parkingId}"</c:if>>
                                        <input type="text" id="parkingName" class="form-control" readonly="readonly" required name="parkingName" value="${data.parking.name}" placeholder="所属停车场"
                                        <c:if test="${type == 6}"> value="${data.parking.name}"</c:if>>
                                        <c:if test="${type != 6}">
                                    </div>
                                    <span class="input-group-btn">
                                        <button id="checkAccount" class="btn btn-success" type="button"  onclick="selectParking();">
                                        <i class="fa fa-arrow-left fa-fw"></i>  选择停车场
                                    </button>
                                    </span>
                                </div>
                                    </c:if>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">车位编号</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="number" value="${data.number}" placeholder="请输入车位编号"
                                       onkeyup="this.value=this.value.replace(/[^\d]/g,'') ">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">所属分区</label>
                            <div class="col-md-9">
                                <select class="form-control" name="zone" id="zone" onchange="xiu()">
                                    <%--<option value="">请选择分区</option>--%>
                                    <c:forEach var="item" items="${zone}" varStatus="status">
                                        <option  <c:if test="${data.zone == item.id}"> selected </c:if>  value="${item.id}">${item.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">有无地锁</label>
                            <div class="col-md-9">
                                <c:if test="${data.switchLock == '1'}">
                                <input type="text" class="form-control" value="有" readonly >
                                <input type="hidden" class="form-control" required name="switchLock" value="${data.switchLock}" >
                                </c:if>
                                <c:if test="${data.switchLock == '2'}">
                                <input type="text" class="form-control"  value="无" readonly >
                                <input type="hidden" class="form-control" required name="switchLock" value="${data.switchLock}">
                                </c:if>
                            </div>
                        </div>
                    </div>
                   <%-- <c:if test="${not empty data.lockId }">--%>
                    <c:if test="${data.switchLock == '1'}">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">地锁编号</label>
                            <div class="col-md-9">
                                <div class="input-group">
                                    <div class="input-icon">
                                        <i class="fa fa-lock fa-fw"></i>
                                        <input id="lockId" class="form-control" type="hidden" name="lockId"  value="${data.lock.id}" >
                                        <input type="text" id="lockName" class="form-control" readonly="readonly" required name="lockName" value="${data.lock.number}" placeholder="选择地锁" >
                                    </div>
                                    <span class="input-group-btn">
                                        <button id="checkLock" class="btn btn-success" type="button"  onclick="selectLock();">
                                        <i class="fa fa-arrow-left fa-fw"></i>  选择地锁
                                    </button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    </c:if>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">车位状态</label>
                            <div class="col-md-9">
                                <select class="form-control" name="switchStatus">
                                    <option <c:if test="${data.switchStatus == '0'}">selected</c:if> value="0">已预定</option>
                                    <option <c:if test="${data.switchStatus == '1'}">selected</c:if> value="1">未预定</option>
                                    <option <c:if test="${data.switchStatus == '2'}">selected</c:if> value="2">已使用</option>
                                    <option <c:if test="${data.switchStatus == '3'}">selected</c:if> value="3">未使用</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">备注</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="intro" value="${data.intro}" placeholder="备注信息">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">x坐标</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="zonex"  id="zonex" placeholder="x坐标" readonly value="${data.zonex}">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group" id="div-image">
                            <label class="control-label col-md-3">y坐标</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="zoney"  id="zoney" placeholder="y坐标" readonly value="${data.zoney}">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6" >
                        <div class="form-group">
                            <label class="control-label col-md-3" >修改车位</label>
                            <div class="col-md-9">
                                <button id="checkParklot" class="btn btn-success" type="button"  onclick="selectParklot();"  >
                                    <i class="fa fa-arrow-left fa-fw"></i>  修改车位位置
                                </button>
                                <input type="hidden" id="tu" value="">
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-6">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-9">
                                <button type="button" class="btn green" onclick="edit();">修改停车位</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_editModule);">取消</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6"> </div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>
<!-- script 开始 -->

<script>
    $(function(){
        //初始化页面
        initPage();

    });

    /**
     * 保存编辑的停车位
     */
    function edit(){
        var param = tools.formParams("edit-module");
        if(tools.valid("edit-module")){
            tools.post("/parkinglot/update",param,function(data){
                if(data.success){
                    layer.msg('停车位修改成功', {icon: 1,time:1000},function(){
                        //刷新列表页面
                        toPage(null);
                        //关闭弹窗
                        layer.close(layer_editModule);
                    });
                }else{
                    tools.errorTip(data.code,data.data);
                }
            });
        }
    }

    /**
     * 2017年5月24日 闫增宝 修改地锁
     */
    function selectLock() {
        $.post("/parkinglot/chooselock",null,function(html){
            window.layer_lockModule = layer.open({
                id:"lockModule",
                type: 1,
                title:"选择地锁",
                area:['900px','600px'],
                resize:false,
                content: html,
                anim:1,
                shadeClose:false,
                cancel: function(){}
            });
        });
    }

    /**
     * 2017年5月24日 闫增宝  修改停车场
     */
    function selectParking(){
        $.post("/parking/chooseParking2",null,function(html){
            window.layer_resModule = layer.open({
                id:"resModule",
                type: 1,
                title:"选择停车场",
                area:['900px','600px'],
                content: html,
                anim:1,
                shadeClose:false,
                cancel: function(){}
            });
        });
    }

    function xiu(){
        //首先获得下拉框的节点对象；
        var zoneId = $("#zone").val();
        if(zoneId!= null && zoneId!=null) {
            document.getElementById("div-image").style.display = "block";
            $.post("/parkinglot/findZoneImg", {"id": zoneId}, function (data) {
                console.log(data);
                $("#tu").attr('value', data.url);
            });
        }
    }

    /**
     * 2017年6月12日 姜延鹏
     * 打开区域图片，选择车位位置
     */
    function selectParklot() {
        var src = document.getElementById("tu").value;
        if(src == null || src ==""){
            layer.msg("请选择有地图的停车场分区");
            return false;
        }
        $.post("/parkinglot/selectParklot", {"src":src}, function(html){
            layer.open({
                id:"selectParklot",
                type: 1,
                title:false,
                area:['1200px','750px'],
                content: html,
                anim:1,
                shadeClose:false,
                yes: function(index, layero){
                    var param = $('#selectParklot').serialize();
                },
                cancel: function(){},
                btn2: function(index, layero){}
            });
        });
    }

</script>
<!-- script 结束 -->